laravel slug for non-english words too

110

// Slugs for non-english words too
Laravel str_slug method in order to work with non-english words too. For example chaning ñ to n and ç to c. I always use this method for this kind of conversion:

function slugify($string, $replace = '-')
{
    $removeasci = iconv('UTF-8', 'ASCII//TRANSLIT', $string);
    $removecomas = str_replace('\'', '', $removeasci);
    $output = preg_replace('/[^a-zA-Z0-9]/', $replace, $removecomas);

    return strtolower($output);
}

Comments

Submit
0 Comments